home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Language/OS - Multiplatform Resource Library
/
LANGUAGE OS.iso
/
smaltalk
/
manchest.lha
/
MANCHESTER
/
manchester
/
4.1
/
background-doits.st
< prev
next >
Wrap
Text File
|
1993-07-24
|
4KB
|
123 lines
" NAME background-doits
AUTHOR miw@cs.man.ac.uk (Mario Wolczko)
FUNCTION Optionally execute doits and inspect in the background
ST-VERSION 4.1
PREREQUISITES
CONFLICTS ParagraphEditor>doIt, ParagraphEditor>inspectIt
DISTRIBUTION world
VERSION 1
DATE 1992
SUMMARY
If you know that the result of a 'do it' or 'inspect' is going to
take a long time, it's sometime desirable for it to run as a
background process, letting you continue interactions.
This goodie modifies the standard 'do it' and 'inspect' behaviour so
that the evaluation is run in the background if a shift key is down
when the evaluation is invoked.
To do this, we have to extend the behaviour of the compiler slightly
so that we can perform the compilation in the foreground, before
running the result of the compilation in the background.
Mario Wolczko
Dept. of Computer Science Internet: mario@cs.man.ac.uk
The University uucp: uknet!!man.cs!!mario
Manchester M13 9PL JANET: mario@uk.ac.man.cs
U.K. Tel: +44-61-275 6146 (FAX: 6236)
______the mushroom project___________________________________
"
'From Objectworks\Smalltalk 4.1, 9 June 1993'!
!ParagraphEditor methodsFor: 'private'!
compileSelection
"Compiler the current text selection as an expression, return a block that will evaulate it."
| result selectionStart oldTextSize selection |
selectionStart := self selectionStartIndex.
oldTextSize := self text size.
selection := self selection.
result :=
self doItReceiver class evaluatorClass new
compile: self selectionAsStream
in: nil
receiver: self doItReceiver
notifying: self
ifFail:
[^self class compilationErrorSignal raise].
self selection asString = selection asString ifFalse:
[self selectFrom: selectionStart "Reselect doIt range after compiler interaction"
to: selectionStart + selection size - 1 + (self text size - oldTextSize)].
SourceFileManager default logChange: self selection string.
^result! !
!ParagraphEditor methodsFor: 'menu messages'!
doIt
"Evaluate the current text selection as an expression"
sensor shiftDown ifTrue: [^self doItBackground].
self class compilationErrorSignal
handle: [:ex | ex returnWith: nil]
do: [self evaluateSelection]!
doItBackground
"Evaluate the current text selection as an expression.
Perform the evaluation as a background process."
| block |
self class compilationErrorSignal
handle: [:ex | ex returnWith: nil]
do: [block := self compileSelection].
block forkAt: Processor userBackgroundPriority!
inspectIt
"Evaluate the current text selection as an expression"
sensor shiftDown ifTrue: [^self inspectItBackground].
self class compilationErrorSignal
handle: [:ex | ex returnWith: nil]
do: [self evaluateSelection inspect]!
inspectItBackground
"Evaluate the current text selection as an expression.
Perform the evaluation as a background process."
| block |
self class compilationErrorSignal
handle: [:ex | ex returnWith: nil]
do: [block := self compileSelection].
[block value inspect] forkAt: Processor userBackgroundPriority! !
!SmalltalkCompiler methodsFor: 'public access'!
compile: textOrStream in: aContext receiver: receiver notifying: aRequestor ifFail: failBlock
"Compiles the sourceStream into a parse tree, then generates code
into a method. If receiver is not nil, then the text can refer to
instance variables of that receiver (the Inspector uses this). If
aContext is not nil, the text can refer to temporaries in that context
(the Debugger uses this). If aRequestor is not nil, then it will
receive a notify:at: message before the attempt to evaluate is aborted.
Finally, a block is returned, which when evaluated, will evaluate the compiled method and return its result."
| methodNode method |
class := (aContext == nil
ifTrue: [receiver]
ifFalse: [aContext homeReceiver]) class.
self from: textOrStream
class: class
context: aContext
notifying: aRequestor.
methodNode := self translate: sourceStream noPattern: true ifFail: [^failBlock value].
method := methodNode generate.
^context == nil
ifTrue: [^[receiver performMethod: method]]
ifFalse: [^[receiver performMethod: method with: context]]! !